﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using NeedForSpeed.Physics;
using NfsEngine;

namespace NeedForSpeed
{
    class TyreSmokeParticleSystem : ParticleSystem
    {
        Vehicle _car;

        int _wheelSwitch;


        static TyreSmokeParticleSystem _instance;
        public static TyreSmokeParticleSystem Instance
        {
            get
            {
                if (_instance == null) _instance = new TyreSmokeParticleSystem();
                return _instance;
            }
        }


        protected override void InitializeSettings(ParticleSettings settings)
        {
            settings.TextureName = "Content/smoke";

            settings.MaxParticles = 200;
            
            settings.Duration = TimeSpan.FromSeconds(0.5f);

            settings.MinHorizontalVelocity = 0;
            settings.MaxHorizontalVelocity = 15;

            settings.MinVerticalVelocity = 5;
            settings.MaxVerticalVelocity = 10;

            // Create a wind effect by tilting the gravity vector sideways.
            settings.Gravity = new Vector3(0, -5, 0);

            settings.EndVelocity = 0.75f;

            //settings.MinRotateSpeed = -1;
            //settings.MaxRotateSpeed = 1;

            settings.MinStartSize = 5;
            settings.MaxStartSize = 10;

            settings.MinEndSize = 20;
            settings.MaxEndSize = 50;
        }


        //public Vector3 Position
        //{
        //    get
        //    {
        //        _wheelSwitch++;
        //        if (_wheelSwitch > 3) _wheelSwitch = 0;

        //        bool frontSkid = _car.FrontSlipFactor > 0.4f;
        //        bool rearSkid = true;// _car.Motor.WheelsSpinning;

        //        if (!frontSkid && rearSkid)
        //        {
        //            if (_wheelSwitch == 0 || _wheelSwitch == 2)
        //            {
        //                return _car.Wheels[2].TrackPositionUnderWheel;
        //            }
        //            else
        //            {
        //                return _car.Wheels[3].TrackPositionUnderWheel;
        //            }
        //        }
        //        else if (frontSkid && !rearSkid)
        //        {
        //            if (_wheelSwitch == 0 || _wheelSwitch == 2)
        //            {
        //                return _car.Wheels[0].TrackPositionUnderWheel;
        //            }
        //            else
        //            {
        //                return _car.Wheels[1].TrackPositionUnderWheel;
        //            }
        //        }
        //        else if (frontSkid && rearSkid)
        //        {
        //            return _car.Wheels[_wheelSwitch].TrackPositionUnderWheel;
        //        }
        //        else
        //        {
        //            return Vector3.Zero;
        //        }
        //    }
        
        //}
    }
}
